/**
 * Copyright (C), 2015-2019, XXX有限公司
 * FileName: GoodsbillMasterServiceImpl
 * Author:   李毅
 * Date:     2019/10/31 16:37
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.ymtms.settlement.service.impl;

import com.ymtms.settlement.dao.GoodsbillMasterMapper;
import com.ymtms.settlement.exception.BalanceException;
import com.ymtms.settlement.pojo.GoodsbillMaster;
import com.ymtms.settlement.service.GoodsbillMasterService;
import com.ymtms.settlement.vo.GridRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 〈一句话功能简述〉<br> 
 * 〈〉
 *
 * @author 李毅
 * @create 2019/10/31
 * @since 1.0.0
 */
@Service
public class GoodsbillMasterServiceImpl implements GoodsbillMasterService {

    @Autowired
    GoodsbillMasterMapper goodsbillMasterMapper;


    @Override
    public List<GoodsbillMaster> findGoodsbillByState(String state, GridRequest gridRequest) {
        Integer end = gridRequest.getLimit();
        Integer start = (gridRequest.getPage()-1)*end;
        List<GoodsbillMaster> goodsbillMasters = goodsbillMasterMapper.selectByState(state, start, end);
        if (goodsbillMasters.isEmpty()){
            throw new BalanceException("查询货运单失败！");
        }
        return  goodsbillMasters;
    }

    @Override
    public Integer findCount(String state) {
      int count = goodsbillMasterMapper.selectCount(state);
      if (count==0) {
          throw new BalanceException("货运单数量查询失败！");
      }
      return count;
    }

    @Override
    public void updateState(Integer gmid) {
       int row = goodsbillMasterMapper.updateState(gmid);
       if (row == 0){
           throw new BalanceException("货运单修改失败！");
       }
    }
}